//
//  confirmViewController.m
//  DrProcessTable
//
//  Created by 白岩凇 on 2016/10/5.
//  Copyright © 2016年 白岩凇. All rights reserved.
//

#import "confirmViewController.h"
#import "SVProgressHUD.h"
#import "BYSCover.h"
#import "GHNetWorkTools.h"
#import "UserInfoModel.h"


#define navigationTitle @"确认"
@interface confirmViewController ()
@property (weak, nonatomic) IBOutlet UIDatePicker *date;
@property (weak, nonatomic) IBOutlet UILabel *remain;
@property (weak, nonatomic) IBOutlet UITextView *userProtocol;


@end

@implementation confirmViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   // self.navigationItem.title=navigationTitle;
    self.date.minimumDate=[NSDate date];
    self.date.maximumDate=[NSDate dateWithTimeIntervalSinceNow:604800];
    self.remain.text = [NSString stringWithFormat:@"%zd", self.model.DoctorPeople];
//    [self.date addTarget:self action:@selector(timeChange) forControlEvents:UIControlEventValueChanged];
}

//- (void)setRemainN:(NSInteger)remainN{
//    _remainN=remainN;
//    self.remain.text=[NSString stringWithFormat:@"%d",(int)remainN];
//}
//点击了确认按钮
- (IBAction)confirmBut:(id)sender {
    
    NSDateFormatter *datefor = [[NSDateFormatter alloc] init];
    [datefor setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *d = [datefor stringFromDate:self.date.date];
    
    NSLog(@"------------------------------%@",d);
//    [BYSCover show];
//    [SVProgressHUD showWithStatus:@"正在挂号"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeGradient];
    [SVProgressHUD showWithStatus:@"正在挂号"];
    
    
    
    NSString *urlstr = @"yuyueguahao";
    //NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:self.model.HospitalName,@"HospitalName",self.model.DepartmentName,@"DepartmentName",self.model.DoctorName,@"DoctorName",self.model.doctorid,@"doctorid",nil];
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:self.model.HospitalName,@"HospitalName",self.model.DepartmentName,@"DepartmentName",self.model.DoctorName,@"DoctorName",@(self.model.doctorid),@"doctorid",d,@"date",@([UserInfoModel shareUserInfoModel].userid),@"userid",nil];
    
    [[GHNetWorkTools sharedTools] requestDataWith:GET urlString:urlstr parameters:dict finishedBlock:^(id result, NSError *error) {
        NSLog(@"%@",result);
        NSInteger code = [[result valueForKey:@"code"] integerValue];
        if (code == 1) {
            [SVProgressHUD showSuccessWithStatus:@"挂号成功"];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                // 1.5s后自动执行这个block里面的代码
               // [SVProgressHUD dismiss];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"setRootVC" object:nil];
            });

        }else{
            [SVProgressHUD showSuccessWithStatus:@"挂号失败"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                // 1.5s后自动执行这个block里面的代码
                [SVProgressHUD dismiss];
            });
        }
        
        
        
    }];
    
    
    
    
}

- (void)hideHUD{
//    [BYSCover hidden];
    [SVProgressHUD showSuccessWithStatus:@"挂号成功"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 1.5s后自动执行这个block里面的代码
        [SVProgressHUD dismiss];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setRootVC" object:nil];
    });
}
- (void)hideHUDs{
    //    [BYSCover hidden];
    [SVProgressHUD showSuccessWithStatus:@"挂号失败"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 1.5s后自动执行这个block里面的代码
        [SVProgressHUD dismiss];
    });
}
//- (void)timeChange{
//    NSLog(@"%@",self.date.date);
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
